package com.yoomiito.app.adapter.my

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.model.my.InviteFriend
import com.yoomiito.app.utils.ImageLoader
import com.yoomiito.app.utils.ImageUtils

@Suppress("DEPRECATION")
class InviteFriendAdAdapter(data: ArrayList<InviteFriend.InviteFriendInfo>?) : BaseQuickAdapter<InviteFriend.InviteFriendInfo, BaseViewHolder>(R.layout.item_invite_friend_bg, data) {

    override fun convert(helper: BaseViewHolder?, item: InviteFriend.InviteFriendInfo?) {
        var iv = helper?.getView<ImageView>(R.id.ad_iv)
//        ImageLoader.getInstance().into(mContext, item?.img_url, helper?.getView(R.id.ad_iv))
        val builder = if (item?.defaultResource == 0)
            Glide.with(mContext).asBitmap().load(item?.img_url)
        else
            Glide.with(mContext).asBitmap().load(item?.defaultResource)

        builder.into(object : SimpleTarget<Bitmap>() {
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                var width = if (App.mWidthPx < resource.width) App.mWidthPx else resource.width
                var height = if(App.mWidthPx<resource.height) App.mWidthPx else resource.height
                iv?.setImageBitmap(Bitmap.createBitmap(resource, 0, 0, width, height))
            }
        })
        helper?.getView<TextView>(R.id.ad_des)?.text = item?.title
    }

}